//
//  SerialConnectDemoAppController.m
//  SerialConnectDemoApp
//
//  Created by David Haselberger on 10.09.08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "SerialConnectDemoAppController.h"


@implementation SerialConnectDemoAppController

- (id)init
{
	if (self = [super init])
	{
		
	}
	
	
	return self;
	
}


- (void)dealloc
{
	[super dealloc];
}


- (void)awakeFromNib
{
	serialConnection = [[SerialConnect alloc] init];
	isActive = [serialConnection activate];
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setReceivedText:) name:@"serialMessageReceived" object:nil];
	
}


- (IBAction)sendText:(id)sender
{
	
	if (isActive)
	{
		[serialConnection sendSerialMessage:[sendTextField stringValue]];
	}else
	{
		[receiveTextField setStringValue:@"No Connection found."];
	}
	
}

- (void)setReceivedText:(NSNotification*)notification
{
	NSString* receivedString = [[NSString alloc] initWithFormat:@"%@", [notification object]];
	[receiveTextField setStringValue:receivedString];
	
}

@end
